home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-01-02 | 3.8 KB | 142 lines | [TEXT/YERK] |
- \ Grep - not a true grep. It does not search for full regular expressions
- \ but only a string of symbols in the set of terminals.
- \ 10/15/84 rw
- \ 1/18/85 cbd eliminated coded searches in favor of string
- \ 2/15/86 cdn restrict file names to print only on match
- \ 9/02/86 cdn Added case sensitivity option
- \ 9/16/86 cdn Added text highlighting: bold line #, underline match, --more--
- \ 9/20/86 cdn Added tab expansion
- \ 12/29/90 rfl modified for sarray path
- \ 5/19/92 rfl now exits more gracefully, and doesn't search yerk folder unless specified
- \ 1/01/94 rfl ffcb clrfcb changed to clear: ffcb; Also sped search up by searching entire
- \ file first..if string found, then search the traditional way.
- \ Also, added save to logfile in dialog; changed pause? to process events
- \
- \ "grflgs" bits:
- \ 0 - case sensitive
- \ 1 - save to logfile
- \ 2 - pause for screen full
-
- :Module grepMod
-
- // vol
- forget dir
-
- String gpattern
- String linBuf
- String target
- 0 value curLin#
- 0 value #lines
- 0 value kBytes
- 0 value #files
-
- \ pause output if option being used
- : more
- grflgs 04 and
- IF curLin# ?lines 3 - >=
- IF 1 tFace ." --More--" 0 tFace key drop CR
- 0 -> curLin#
- THEN
- THEN ;
-
- false value getOut
- : pause? false -> getOut
- next: fevent
- IF 2drop cr .pause (key) cr 0 -> out 32 >
- IF true ELSE false THEN
- ELSE false
- THEN -> getOut
- ;
-
- \ ( -- ) ( VARS: linecount, mybuf ) n.b. also assumes gpattern set
- : SearchFile { \ line# .name? -- } pause?
- 1 ++> #files
- topfile size: topfile read: linBuf drop
- size: topfile ++> KBytes
- grflgs 01 and 0= IF uc: linBuf 2drop THEN
- start: linBuf get: gpattern indexOf: linBuf
- IF drop
- 0 moveto: topfile drop
- 0 -> line# 1 -> .name?
- BEGIN pause?
- topFile 80 readLine: linBuf not getOut not and
- WHILE
- 1 ++> line#
- target =: linBuf start: target
- grflgs 01 and 0= IF uc: target 2drop THEN
- get: gpattern indexOf: target
- IF .name?
- IF more cr getName: topFile type ." :" cr 2 ++> curLin#
- 0 -> .name?
- THEN
- more
- 1 tFace \ bold
- line# 3 .r ." ->" start: linBuf
- 0 tFace \ plain
- dup substr: linBuf type
- 4 tFace \ underline
- dup moveTo: linBuf
- size: gpattern dup substr: linBuf type
- + dup moveTo: linBuf
- 0 tFace \ plain
- size: linBuf swap - substr: linBuf type cr 1 ++> curLin#
- THEN
- REPEAT
- line# ++> #lines
- THEN
- ;
-
- \ GREP - Will search through all text
- \ files for the string specified in object gpattern; printing out the
- \ file name, line number and line for all occurrences of the string it
- \ locates.
- : (grep) { addr len \ gcurs dirid -- }
- grFlgs 02 and IF +file THEN
- false -> getOut
- watchcurs 0 -> #lines 0 -> curLin# 0 -> kBytes 0 -> #files
- curs -> gcurs -curs \ Preserve cursor status
- new: loadFile new: gpattern new: target
- addr len str255 -base count put: gPattern
- ." Searching for: " print: gPattern CR
- grflgs 01 and IF ." -Case sensitive-" CR
- ELSE uc: gPattern 2drop THEN
- new: linBuf
- HFS? IF limit: path ELSE 1 THEN 0
- DO path IF i at: path name: fFcb
- ELSE clear: fFcb
- THEN
- i at: path swap drop 0>
- IF Filecount 1+ 1
- DO i getidxfile
- IF pad count " System" s= not
- IF pad count name: topFile
- getdirid: ffcb setdirid: topfile
- openReadOnly: topFile ?error 132
- GetFileInfo: topFile drop
- GetType: topFile txType =
- IF searchfile THEN
- close: topFile drop
- THEN
- THEN
- getOut IF Leave THEN
- LOOP
- getOut IF Leave THEN
- THEN
- LOOP
- gcurs -> curs \ Restore cursor status
- remove: loadFile release: gpattern release: target
- release: linBuf
- \ cr #lines . ." lines searched." cr
- cr #files . ." files, "
- kBytes 1000000 >
- IF kBytes 1000 / 0 <# # # # ascii . hold #s #> type ." MBytes"
- ELSE kBytes 100 / 0 <# # ascii . hold #s #> type ." KBytes"
- THEN ." searched." cr
- arrowcurs
- grFlgs 02 and IF -file THEN
- ;
-
- : grep word" count (grep) ;
-
- ;Module
-